#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>

#define PRESS_UP	0
#define PRESS_DOWN	1
#define PRESS_LEFT	2
#define PRESS_RIGHT	3
#define PRESS_ENTER	4
#define PRESS_ESC	5
#define PRESS_HOME	6

 Display *display;

 void init_sim(){
	display = XOpenDisplay(NULL);
 }

 int press(int key){
	unsigned int keycode;

	if(key == PRESS_UP)
		keycode = XKeysymToKeycode(display, XK_Up);
	else if(key == PRESS_DOWN)
		keycode = XKeysymToKeycode(display, XK_Down);
	else if(key == PRESS_LEFT)
		keycode = XKeysymToKeycode(display, XK_Left);
	else if(key == PRESS_RIGHT)
		keycode = XKeysymToKeycode(display, XK_Right);
	else if(key == PRESS_ENTER)
		keycode = XKeysymToKeycode(display, XK_Return);
	else if(key == PRESS_ESC)
		keycode = XKeysymToKeycode(display, XK_Escape);
	else if(key == PRESS_HOME)
		keycode = XKeysymToKeycode(display, XK_Home);

	XTestFakeKeyEvent(display, keycode, True, 0);
	XTestFakeKeyEvent(display, keycode, False, 0);
	XFlush(display);
	return 0;
}

int main(int argc, char *argv[]){
	press(PRESS_UP);
}
